<?php


namespace App\Models\Workflow;

use App\Models\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class WorkflowNode extends Model
{
    protected $table = 'akbus_workflow_node';

    protected $fillable = [
        'node_name',
        'node_key',
        'role_id',
        'type',
        'workflow_id',
    ];

    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [
    ];

    /**
     * 类型转化
     *
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
    ];

    /**
     * 对应流程
     *
     * @return BelongsTo
     */
    public function workflow(): BelongsTo
    {
        return $this->belongsTo(Workflow::class);
    }

    /**
     *单据现在状态
     *
     * @return HasOne
     */
    public function process(): HasOne
    {
        return $this->hasOne(WorkflowProcess::class, 'node_id');
    }

    /**
     *单据现在状态
     *
     * @return HasMany
     */
    public function logs(): HasMany
    {
        return $this->hasmany(WorkflowLog::class, 'node_id');
    }
}
